package com.xszx.server.service;

import com.xszx.server.dto.Page;
import com.xszx.server.dto.SortDto;
import com.xszx.server.entity.CourseContent;
import com.xszx.server.mapper.CourseContentMapper;
import com.xszx.server.util.UuidUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;

@Service
public class CourseContentService {
    @Resource
    private CourseContentMapper courseContentMapper;
    /**
     * 新增或者删除信息
     * @param courseContent
     * @return
     */
    public String save(CourseContent courseContent){
            return (courseContentMapper.insert(courseContent)>0)?"添加成功":"添加失败";
    }
    /**
     * 新增或者更新信息
     * @param courseContent
     * @return
     */
    public String saveOrUpdate(CourseContent courseContent){
        CourseContent content = this.getCourseContent(courseContent.getId());
        if(content == null){
            return (courseContentMapper.insert(courseContent)>0)?"添加成功":"添加失败";
        }else{
            return (courseContentMapper.updateByPrimaryKeyWithBLOBs(courseContent)>0)?"更新成功":"更新失败";
        }
    }
    /**
     * 物理删除课程内容
     * @param id
     * @return
     */
    public int del(String id){
        return courseContentMapper.deleteByPrimaryKey(id);
    }
     /**
     * 获取单个课程内容
     * @return
     */
    public CourseContent getCourseContent(String id){
        return courseContentMapper.selectByPrimaryKey(id);
    }
}
